package cn.kgc.tcst004.maoqichao.crowdfundingadminspringboot.service;

import cn.kgc.tcst004.maoqichao.crowdfundingadminspringboot.mapper.AdvertiseMapper;
import cn.kgc.tcst004.maoqichao.crowdfundingadminspringboot.pojo.Advertise;
import cn.kgc.tcst004.maoqichao.crowdfundingadminspringboot.pojo.AdvertiseExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AdvertiseServiceImpI implements AdvertiseService{
    @Resource
    AdvertiseMapper advertiseMapper;
    @Override
    public PageInfo<Advertise> queryForKeywordAdvertise(Integer pageNum, Integer pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        AdvertiseExample advertiseExample = new AdvertiseExample();
        AdvertiseExample.Criteria criteria = advertiseExample.createCriteria();
        criteria.andNameLike("%"+keyword+"%");
        List<Advertise> advertises = advertiseMapper.selectByExample(advertiseExample);
        return new PageInfo<>(advertises);
    }

    @Override
    public List<Advertise> getAdvertiseListByIdList(List<Integer> advertiseIdList) {
        AdvertiseExample advertiseExample = new AdvertiseExample();
        AdvertiseExample.Criteria criteria = advertiseExample.createCriteria();
        AdvertiseExample.Criteria criteria1 = criteria.andIdIn(advertiseIdList);
        List<Advertise> advertises = advertiseMapper.selectByExample(advertiseExample);
        return advertises;
    }

    @Override
    public void batchRemove(List<Integer> advertiseIdList) {
        AdvertiseExample advertiseExample = new AdvertiseExample();
        AdvertiseExample.Criteria criteria = advertiseExample.createCriteria();
        criteria.andIdIn(advertiseIdList);
        advertiseMapper.deleteByExample(advertiseExample);
    }

    @Override
    public void saveAdvertise(Advertise advertise) {
            advertiseMapper.insert(advertise);
    }

    @Override
    public void updateAdvertise(Advertise advertise) {
        advertiseMapper.updateByPrimaryKey(advertise);
    }

    @Override
    public Advertise selectByUpdate(Integer id) {

        return advertiseMapper.selectByPrimaryKey(id);
    }
}
